﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ePlanet.ArchiveMange.Models;
using ePlanet.SingleWell.Models;

namespace Web.Views.DataManage.Models
{
    public class ArchiveTypeViewModel
    {
        public decimal TypeID {get;set;}
        public string ArchiveMenu{get;set;}
        public decimal ParentID { get; set; }
        public string TypeCode { get; set; }
        public static ArchiveMangeModal.ARCHIVEMENURow ViewToArchiveMenuRow(ArchiveTypeViewModel model, ArchiveMangeModal.ARCHIVEMENURow row)
        {
            try {
                row.TYPEID = model.TypeID;
                row.ARCHIVEMENU = model.ArchiveMenu;
                row.PARENTID = model.ParentID;
                row.TYPECODE = model.TypeCode;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return row;
        }

        public static ArchiveTypeViewModel ArchiveMenuRowToView(ArchiveMangeModal.ARCHIVEMENURow row)
        {
            ArchiveTypeViewModel model = new ArchiveTypeViewModel();
            try {
                model.TypeID = row.TYPEID;
                model.ArchiveMenu = row.ARCHIVEMENU;
                model.ParentID = row.PARENTID;
                model.TypeCode = row.TYPECODE;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return model;
        }
    }

    public class ArchiveTypeUpdateModel
    {
        public List<ArchiveTypeViewModel> InsertedRows { get; set; }
        public List<ArchiveTypeViewModel> UpdatedRows { get; set; }
        public List<ArchiveTypeViewModel> DeletedRows { get; set; }
    }

    public class WellCatalogViewModel
    {
        public string WellcatalogId { get; set; }
        public string CatalogDescript { get; set; }
        public string ParentID { get; set; }
        public string CatelogSort { get; set; }
        public decimal? IsWellCode { get; set; }
        public static WellCatalog.WELLCATALOGRow ViewToWellCatalogRow(WellCatalogViewModel model, WellCatalog.WELLCATALOGRow row)
        {
            try
            {
                row.WELLCATALOGID = model.WellcatalogId;
                row.CATALOGDESCRIPT = model.CatalogDescript;
                row.PARENTID = model.ParentID;
                row.CATELOGSORT = model.CatelogSort;
                if (model.IsWellCode.HasValue)
                {
                    row.ISWELLCODE = model.IsWellCode.Value;
                }
                else
                {
                    row.SetISWELLCODENull();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return row;
        }

        public static WellCatalogViewModel WellCatalogRowToView(WellCatalog.WELLCATALOGRow row)
        {
            WellCatalogViewModel model = new WellCatalogViewModel();
            try
            {
                model.WellcatalogId = row.WELLCATALOGID;
                model.CatalogDescript = row.CATALOGDESCRIPT;
                model.ParentID = row.PARENTID;
                model.CatelogSort = row.CATELOGSORT;
                if (!row.IsISWELLCODENull())
                {
                    model.IsWellCode = row.ISWELLCODE;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return model;
        }
    }

    public class WellCatalogUpdateModel
    {
        public List<WellCatalogViewModel> InsertedRows { get; set; }
        public List<WellCatalogViewModel> UpdatedRows { get; set; }
        public List<WellCatalogViewModel> DeletedRows { get; set; }
    }
}